<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('物业详情') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('所在层')" prop="layer">
        <el-input
          v-model="queryParams.layer"
          :placeholder="$t('所在层')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('出租状态')" prop="rentalStatus">
        <el-select v-model="queryParams.rentalStatus" :placeholder="$t('出租状态')" clearable>
          <el-option
            v-for="dict in rentalStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="!isRoomNumber"
          v-hasPermi="['deal:license:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t('导出') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dealLicenseDetailsList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <!--      <el-table-column :label="$t('主表id')" align="center" prop="licenseId" />-->
      <el-table-column :label="$t('楼号')" align="center" prop="floor" min-width="120" />
      <el-table-column :label="$t('所在层')" align="center" prop="layer" min-width="120" />
      <el-table-column :label="$t('房号')" align="center" prop="roomNo" min-width="120" />
      <el-table-column :label="$t('建筑面积')" align="center" prop="constructionArea" min-width="120" />
      <el-table-column :label="$t('用途')" align="center" prop="use" :formatter="useFormat" min-width="120" />
      <el-table-column :label="$t('证号')" align="center" prop="certificateNumber" min-width="270" />
      <el-table-column :label="$t('租约')" align="center" prop="leaseName" min-width="280" class-name="dealContractPlan">
        <template slot-scope="scope">
          <div class="plan">
            <div v-for="(value,index) in scope.row.dealLicenseDetails" :key="index">
              <el-link type="primary" @click="updateHandle(value)"><span>{{ value.leaseName }}</span></el-link>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('租约到期日期')" align="center" prop="leaseEndDate" min-width="120" class-name="dealContractPlan">
        <template slot-scope="scope">
          <div class="plan">
            <div v-for="(value,index) in scope.row.dealLicenseDetails" :key="index">
              <span>{{ parseTime(value.leaseEndDate) }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('出租状态')" align="center" prop="rentalStatus" min-width="120" class-name="dealContractPlan">
        <template slot-scope="scope">
          <div class="plan">
            <div v-for="(value,index) in scope.row.dealLicenseDetails" :key="index">
              <span>{{ rentalStatusFormat(value) }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="$t('租约管理')" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealLeaseForm ref="dealLeaseForm" />
    </el-dialog>
  </div>
</template>

<script>
import { findDetailsList } from '@/api/deal/license/dealLicenseDetails'
import dealLeaseForm from '@/views/deal/immovable/dealLeaseForm'
export default {
  components: {
    dealLeaseForm
  },
  data() {
      return {
          isRoomNumber: false,
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 物业详情表格数据
          dealLicenseDetailsList: [],
          // 弹出层标题
          title: '物业详情',
          // 是否显示弹出层
          formOpen: false,
        // 用途字典
        useOptions: [],
        // 出租状态字典
        rentalStatusOptions: [],

          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              licenseId: undefined,
              layer: undefined,
              rentalStatus: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('license_details_use').then(response => {
          this.useOptions = response.data
      })
      this.getDicts('license_rental_status').then(response => {
        this.rentalStatusOptions = response.data
      })
  },
  methods: {
    /** 查询物业详情列表 */
    getList() {
        this.loading = true
      findDetailsList(this.queryParams).then(response => {
            this.dealLicenseDetailsList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 用途字典翻译
    useFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.useOptions, row.use)
    },
    // 出租状态字典翻译
    rentalStatusFormat(row) {
      return this.selectDictLabel(this.rentalStatusOptions, row.rentalStatus)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            licenseId: undefined,
            floor: undefined,
            layer: undefined,
            roomNo: undefined,
            constructionArea: undefined,
            use: undefined,
            certificateNumber: undefined,
            leaseId: undefined,
            leaseName: undefined,
            leaseEndDate: undefined,
            rentalStatus: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    // /** 新增按钮操作 */
    // addHandle() {
    //     this.formOpen = true
    //     this.$nextTick(() => {
    //         this.$refs.dealLicenseDetailsForm.init(null)
    //     })
    // },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
          // 调用form页面的 init 方法初始化数据
          this.$refs.dealLeaseForm.init({ id: row.leaseId })
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/license/dealLicenseDetails/export', this.queryParams)
    }
  }
}
</script>
